#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MOD = 1e9 + 7;

ll pd(ll base, ll exp, ll mod)
{
    ll res = 1;
    base %= mod;
    while (exp > 0)
    {
        if (exp & 1LL)
        {
            res = res * base % mod;
        }
        base = base * base % mod;
        exp >>= 1LL;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int m, q;
    cin >> m >> q;
    vector<int> que(q);
    for (auto &x : que)
        cin >> x;

    int max_n = 0;
    for (auto n : que)
        max_n = max(max_n, n);

    if (m == 1)
    {

        for (auto n : que)
        {
            if (n == 0)
            {
                cout << "1\n";
            }
            else
            {
                ll ans = pd(2, n - 1, MOD);
                cout << ans << "\n";
            }
        }
        return 0;
    }

    vector<ll> dpp(m + 2, 0);
    dpp[1] = 1;

    for (int i = 0; i < max_n; ++i)
    {
        vector<ll> dpc(m + 2, 0);

        for (int j = 1; j <= m; ++j)
        {
            if (dpp[j] == 0)
                continue;

            ll de = (dpp[j] * (2LL * j)) % MOD;
            dpc[j] = (dpc[j] + de) % MOD;

            if (j < m)
            {

                ll di = (dpp[j] * (j)) % MOD;
                dpc[j + 1] = (dpc[j + 1] + di) % MOD;
            }
        }
        dpp = dpc;
    }

    vector<vector<ll>> dpa(max_n + 1, vector<ll>(m + 2, 0));
    dpa[0][1] = 1;

    for (int del = 0; del < max_n; ++del)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (dpa[del][j] == 0)
                continue;

            ll we = (dpa[del][j] * (2LL * j)) % MOD;
            dpa[del + 1][j] = (dpa[del + 1][j] + we) % MOD;

            if (j < m)
            {
                ll wi = (dpa[del][j] * j) % MOD;
                dpa[del + 1][j + 1] = (dpa[del + 1][j + 1] + wi) % MOD;
            }
        }
    }

    for (auto n : que)
    {
        if (n == 0)
        {

            cout << "1\n";
            continue;
        }
        if (n > max_n)
        {

            cout << "0\n";
            continue;
        }

        ll ans = 0;
        for (int j = 1; j <= m; ++j)
        {
            ans = (ans + dpa[n][j]) % MOD;
        }

        cout << ans << "\n";
    }
}
